<?php
/**
 * created by zzy
 * date: 2017/10/24 9:28
 */

namespace App\Api\Service\Common\Controllers;

use App\Eloquent\Ygt\ImgUpload;
use App\Eloquent\Ygt\Order;
use App\Eloquent\Ygt\Product;
use App\Eloquent\Ygt\Stock;
use Framework\BaseClass\Api\Controller;
use App\Engine\Func;

class IndexController extends Controller
{

    //二维码
    public function qrcode()
    {
        $type               = request('type', 0);
        $qrcodeStr          = 'type:1';
        switch ($type)
        {
            case 1:
                //材料二维码
                $productId      = request('id', 0);
                $where          = ['id'=>$productId];
                $info           = Product::getInfo($where);
                if($info)
                {
                    $qrcodeStr  .= ',id:'.$productId;
                }
                break;
            case 2:
                //入库
                $stockId        = request('id', 0);
                $where          = ['id'=>$stockId];
                $info           = Stock::getInfo($where);
                $qrcodeStr      = '';
                if($info)
                {
                    $waterNo    = $info->water_no;
                    $qrcodeStr  = '1-'.$stockId.'-'.$waterNo;
                }
                break;
            default:
                $qrcodeStr      = '';
        }
        $result             = Func::qrcode($qrcodeStr);
        echo $result;exit;
    }

    //获取大图
    public function getImg()
    {
        $type               = request('type', 0);
        $idStr              = request('ids', '');
        $result             = $imgIdArr = [];
        if($idStr != '')
        {
            $idArr          = explode(',',$idStr);
            switch ($type)
            {
                case 1:
                    //订单id
                    $orderInfo = Order::where(['id'=>$idStr])->first();
                    if ($orderInfo->production_case_diagram) {
                        $imgIdArr       = explode(',',$orderInfo->production_case_diagram);
                    }
                    break;
                default:
                    $imgIdArr       = $idArr;
            }
            $where          = ['id'=>['in',$imgIdArr]];
            $fields         = 'id,img_url';
            $imgList        = ImgUpload::getList($where,$fields)->toArray();
            foreach($imgList as $key=>$val)
            {
                $imgPath    = $val['img_url'];
                $imgUrl     = Func::getImgUrlHttp( $imgPath,false);
                $result[]   = $imgUrl;
            }
        }
        return $result;
    }
    //获取结算方式
    public function getPayList()
    {
        //$from值不同表示来源不同
        $from               = request('from', 1);
        switch ($from)
        {
            case 1:
                //来自客户
                $result     = Func::getPayTypeList();
                break;
            case 2:
                //来自供应商
                $result     = Func::getPayTypeList();
                break;
            default:
                $result     = [];
        }
        return $result;
    }


}